﻿#define TRACE
//#undef TRACE

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;

public class LoginScreen : MonoBehaviour
{
	#region login section
	[SerializeField]
	private InputField accountInput;
	[SerializeField]
	private InputField pwdInput;
	[SerializeField]
	private Button loginBtn;

	[SerializeField]
	private GameObject login_img_;
	#endregion

	#region signup section
	[SerializeField]
	private InputField account_input_signup_;
	[SerializeField]
	private InputField pwd_input_signup_;
	[SerializeField]
	private InputField pwd_input_repeted__signup_;
	[SerializeField]
	private Button signup_btn_;

	[SerializeField]
	private GameObject signup_img_;
	#endregion

	// Use this for initialization
	void Start()
	{

	}

	// Update is called once per frame
	void Update()
	{

	}

	public void on_login_bnt_clicked()
	{
		int len = accountInput.text.Length;
		if (len == 0 || len > 6)
		{
			Debug.Log("   账号不合法 ！\n");

			return;
		}
		len = pwdInput.text.Length;
		if (len == 0 || len > 6)
		{
			Debug.Log("   密码不合法 ！\n");
			return;
		}

		loginBtn.interactable = false;

		// @TODO-验证通过 申请登陆  Verification succeeds and start to login

	}

	public void on_signup_bnt_clicked()
	{
		int len = account_input_signup_.text.Length;
		if (len == 0 || len > 6)
		{
			Debug.Log("   account name wrong ！\n");
			return;
		}

		len = pwd_input_signup_.text.Length;
		if (len == 0 || len > 6)
		{
			Debug.Log("   password wrong ！\n");
			return;
		}

		if (!pwd_input_repeted__signup_.text.Equals(pwd_input_signup_.text))
		{
			Debug.Log("   password not equals ！\n");
			return;
		}

		// 可以向server注册账号

		// 重置可见性
		account_input_signup_.text = pwd_input_signup_.text = pwd_input_repeted__signup_.text = "";
		login_img_.SetActive(true);
		signup_img_.SetActive(false);

	}

	public void on_close_signup_win_bnt_clicked()
	{
		// 重置可见性
		account_input_signup_.text = pwd_input_signup_.text = pwd_input_repeted__signup_.text = "";
		login_img_.SetActive(true);
		signup_img_.SetActive(false);
	}
}
